# coding=utf-8
# Django settings for ManekiNeko project.
from ConfigParser import ConfigParser
import os

PROJECT_ROOT_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
PROJECT_ENV = 'localtest'

confer = ConfigParser()
confer.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs/project_%s.ini' % PROJECT_ENV))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

#数据库配置
DATABASES = {
    'default': {
        'ENGINE'  : confer.get('db', 'engine'),   # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME'    : confer.get('db', 'name'),     # Or path to database file if using sqlite3.
        'USER'    : confer.get('db', 'user'),     # Not used with sqlite3.
        'PASSWORD': confer.get('db', 'password'), # Not used with sqlite3.
        'HOST'    : confer.get('db', 'host'),     # Set to empty string for localhost. Not used with sqlite3.
        'PORT'    : confer.get('db', 'port'),     # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Asia/Shanghai'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'zh-cn'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(PROJECT_ROOT_PATH, 'static'),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'j(^d80dgofa_elx=xm-p+(vb)p68r*^lsbn*s5w%7we&amp;jm4zfl'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #manekineko global settings 缓存
#    'genesisbros.manekineko.middleware.GlobalSettingsMiddleware',
#    'genesisbros.manekineko.middleware.NekoUserAuthMiddleware',
    #KjsSoft app Eagleye user auth middleware
    'com.kjssoft.eagleye.middleware.EagleyeAuthMiddleware',
    'com.kjssoft.eagleye.middleware.EagleyeAppMiddleware',
    #文件上传处理器
    'com.kjssoft.rainbow.middleware.RainbowPhotoUploadMiddleware',
    'com.kjssoft.rainbow.middleware.RainbowUserPermissionMiddleware',
    'com.kjssoft.rainbow.middleware.RainbowExceptionHandleMiddleware',

    'com.kjssoft.rainbow.image.middleware.RainbowImageUploadMiddleware',
)

ROOT_URLCONF = 'settings.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'settings.wsgi.application'

TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT_PATH, 'templates'),
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    #kjs installed apps
    #工具类
    'com.kjssoft.common.ant',
    #项目模型元数据
    'com.kjssoft.common.beehive',
    #账户管理系统
    'com.kjssoft.eagleye',
    'com.kjssoft.eagleye.social',
    #rainbow
    'com.kjssoft.rainbow.album',
    'com.kjssoft.rainbow.frame',
    'com.kjssoft.rainbow.label',
    'com.kjssoft.rainbow.category',
    #rainbow image
    'com.kjssoft.common.file',
    'com.kjssoft.rainbow.image',
)

#发送邮件的公共设置
EMAIL_HOST          = confer.get('email', 'host')
EMAIL_PORT          = confer.get('email', 'port')
EMAIL_HOST_USER     = confer.get('email', 'user')
EMAIL_HOST_PASSWORD = confer.get('email', 'password')
EMAIL_USE_TLS       = confer.getboolean('email', 'tls')

#项目缓存设置
CACHE_BACKEND = confer.get('cache', 'cache_backend')

#文件上传设置
#FILE_UPLOAD_MAX_MEMORY_SIZE = 3
FILE_UPLOAD_TEMP_DIR = confer.get('upload', 'temp_dir')
FILE_UPLOAD_HANDLERS = (
    'django.core.files.uploadhandler.MemoryFileUploadHandler',
    'django.core.files.uploadhandler.TemporaryFileUploadHandler',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOG_OUT_PUT = os.path.join(PROJECT_ROOT_PATH, 'out/logs')

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)-23s - %(levelname)-8s - %(pathname)-80s - %(funcName)-30s - %(lineno)d - %(message)s'
        },
        },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'stdout': {
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter':'standard',
        },
        'file': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(LOG_OUT_PUT,'kjssoft.log'), #,
            'maxBytes': 1024*1024*25, # 5 MB
            'backupCount': 5,
            'formatter':'standard',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'kjssoft.rainbow':{
            'handlers': ['stdout'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'kjssoft.eagleye':{
            'handlers': ['stdout'],
            'level': 'DEBUG',
            'propagate': True,
        }
    }
}